package store.dao;

import store.model.Cart;
import store.model.Recover;

import java.sql.SQLException;
import java.util.List;

public class CartDao {

    private static final Recover<Cart> cartRecover = new Cart.CartRecover();

    private static final DBUtils<Cart> dbUtils;
    static {
        dbUtils = new DBUtils<>();
    }

    public int insert(Cart cart) throws SQLException, ClassNotFoundException {
        String sql = "insert into cart(goods_no, account_id, num) values(?,?,?)";
        return dbUtils.executeUpdate(sql, cart.getGoodsNO(),
                cart.getAccountId(),
                cart.getNum());
    }

    public List<Cart> selectByAccountId(int accountId) throws SQLException, ClassNotFoundException {
        String sql ="select * from cart where account_id = ?";
        return dbUtils.executeQuery1(sql, cartRecover, accountId);
    }

}
